package com.liuchen.boot.config.tomcat;

import com.liuchen.common.util.PropertiesEnvUtils;
import org.apache.log4j.Logger;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Map;

/**
 * tomcat
 */
@Configuration
public class WebServerConfiguration {

    //日志
    private Logger log = Logger.getLogger(getClass().getName());

    @Bean
    public EmbeddedServletContainerFactory createEmbeddedServletContainerFactory() {
        Map<String, String> rb = PropertiesEnvUtils.getPropertiesMap("tomcat");
        int port = Integer.parseInt(rb.get("tomcatPort"));
        log.info("配置tomcat参数:" + port);
        TomcatEmbeddedServletContainerFactory tomcatFactory = new TomcatEmbeddedServletContainerFactory();
        tomcatFactory.setPort(port);
        tomcatFactory.addConnectorCustomizers(new MyTomcatConnectorCustomizer(rb));
        return tomcatFactory;
    }
}

